//    Copyright (C) Kherty.  All rights reserved.
namespace OpenLS.Spreadsheet.Parsing
{
    class KeywordCreator : TokenCreator
    {
        public KeywordCreator(Keyword t)
        {
            tokenType = t;
            matchString = t.Name();
            Length = matchString.Length;
        }

        readonly int Length;
        readonly string matchString;
        readonly Keyword tokenType;
        public override int MatchSize()
        {
            return Length;
        }
        public override Token Match(Lexer l)
        {
            for (int i = 0; i < Length; i++)
            {
                char c = l[i + l.Position];
                if (c != matchString[i])
                    return null;
            }
            if (CharTypeManager.IsAlphaNum_(l[Length + l.Position]))
                return null;
            return tokenType.Create();
        }
        public override char[] FirstChars()
        {
            return new char[] { matchString[0] };
        }
    }
}